/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.edu.kamai.xmlparser.listening;

import com.edu.kamai.xml.beans.paperXML;
import com.edu.kamai.xml.beans.choiceXML;
import com.edu.kamai.xml.beans.listening.listeningQuestion;
import com.edu.kamai.xml.beans.listening.listeningXML;
import com.edu.kamai.xmlparser.paperGeneration;
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;

/**
 *
 * @author xyzhu
 */
public class listeningPaperGeneration extends paperGeneration {
    public listeningPaperGeneration(paperXML xml){
        //super();
        super(xml.getPaperRoleID());
        this.rxml = (listeningXML) xml;
    }
    
    public void generateBody(){
        document = new Document();
        Element root = generateHead();
        int numOfQuestion = rxml.getListeningquestionList().size();
        for(int i = 0;i < numOfQuestion; i++){
            listeningQuestion lq = rxml.getListeningquestionList().get(i);
            Element child = new Element("ListeningQestion");
            child.addContent(new Element("MainTxt").setText(lq.getMainTxt()));
            child.addContent(new Element("Title").setText(lq.getTitle()));
            child.addContent(new Element("Desc").setText(lq.getDescription()));
            child.addContent(new Element("mp3path").setText(lq.getMP3Path()));
            child.addContent(new Element("TimeLimit").setText(lq.getTimeLimit()+""));
            
            int cSize = lq.getChoices().size();
            Element choices = new Element("choices");
            for(int j=0;j< cSize;j++){
                Element choice = new Element("choice");
                choiceXML cxml = lq.getChoices().get(j);
                choice.addContent(new Element("ChoiseMainTxt").
                        setText(cxml.getMainTxt()));
                choice.addContent(new Element("ChoiseKey").
                        setText(cxml.getKeys()));
                
                List<String> choicesTxt = cxml.getChoicesTxt();
                Element optionTxt = new Element("optionTxts");
                int cmSize = choicesTxt.size();
                for(int k=0;k<cmSize;k++){
                    optionTxt.addContent(new Element("optionTxt").
                            setText(choicesTxt.get(k)));
                }
                choice.addContent(optionTxt);
                //child.addContent(choice);
                choices.addContent(choice);
            }
            child.addContent(choices);
            root.addContent(child);
            //root.addContent(choices);
            
        }
        document.setContent(root);
    }
    
    private listeningXML rxml;
    
    
}
